<#-- @ftlvariable name="roleId" type="java.lang.String" -->
<#include "/_inc/_layout.ftl">
<@header/>
<#assign grid_url=html.urls("/auth/urmap/rolegrid?roleId=${roleId}")>
<#assign add_url=html.urls("/auth/urmap/roleselect?roleId=${roleId}")>
<#assign delete_url=html.urls("/auth/urmap/roledelete?roleId=${roleId}")>
<div id="gridtoolbar">
    <form id="gridform" class="jxform jxlayout-form">
        <table>
            <tr>
                <td>
                    <input class="form-control w-200px" name="name" placeholder="请输入姓名/账号关键字">
                </td>
                <td>
                    <button class="btn btn-primary ml-5" type="submit">
                        <i class="fa fa-search"></i> 查询
                    </button>

                    <a id="btnAddUser" class="btn btn-success" data-url="${add_url}">
                        <i class="icon-plus"></i> 添加用户
                    </a>

                    <a id="btnDeleteUser" class="btn btn-danger" data-url="${delete_url}">
                        <i class="icon-trash"></i> 移除用户
                    </a>
                </td>
            </tr>
        </table>
    </form>
</div>
<table id="grid" class="jxgrid" data-options="url: '${grid_url}',onDblClickRow: jx.auth.onUserGridDblClickRow,form: '#gridform',toolbar: '#gridtoolbar'">
    <thead>
    <tr>
        <th data-options="field: 'ck',checkbox:true"></th>
        <th data-options="title: '姓名', field: 'name', width: 100, align: 'center'"></th>
        <th data-options="title: '账号', field: 'account', width: 200, sortable: true, align: 'center'"></th>
        <th data-options="title: '部门', field: 'departmentName', width: 200, align: 'center'"></th>
    </tr>
    </thead>
</table>
<@footer>
<script>
    window.reloadGridData = function () {
        $('#grid').jxgrid().reloadGridData();
    }

    $('#btnAddUser').click(function () {
        var url = $(this).data('url');
        jx.dialog({
            title: '选择角色成员',
            url: url,
            width: '600px',
            height: '80%'
        });
    });

    $('#btnDeleteUser').click(function () {
        var gridInstance = $('#grid').jxgrid();
        if (!gridInstance.hasCheckedRow()) return;
        var url = $(this).data('url');
        var ids = gridInstance.getCheckedRowIds();
        jx.delete({
            url: url,
            data: {userIds: ids.join()},
            confirm: '注：您确定要移除当前选中的成员吗？',
            success: function (result) {
                gridInstance.reloadGridData();
            }
        });
    });
</script>
</@footer>